#include"Punct_stream.h"

bool Punct_stream::is_whitespace(char c)
{
  for(char temp:white)
    if(c==temp) return true;
  return false;
}

Punct_stream& Punct_stream::operator>>(string& s)
{
  while(!(buffer>>s))
    {
      if(buffer.bad()||!buffer.good())
	return *this;

      string line;
      getline(source,line);

      for(char& ch:line)
	{
	if(is_whitespace(ch))
	  ch=' ';
	else if(!sensitive)
	  ch=tolower(ch);
	}

      buffer.str(line);  //put the line into istringstream 
    }
  return *this;
}

Punct_stream::operator bool()
{
  return !(source.fail()||source.bad())&&source.good();
}
